﻿using System;
using System.Web;

namespace Douban.Api.Authorization
{
    public class OAuth : OAuthBase
    {
        public string GenerateRequestUrl(
            Uri url, string consumerKey, string consumerSecret, string token, 
            string tokenSecret, string httpMethod, string timeStamp, string nonce)
        {
            string normalizedUrl = null;
            string normalizedParameters = null;

            string signature = GenerateSignature(
                url, consumerKey, consumerSecret, token, tokenSecret, httpMethod,
                timeStamp, nonce, out normalizedUrl, out normalizedParameters);

            return GenerateRequestUrl(normalizedUrl, normalizedParameters, signature);
        }

        public string GenerateRequestUrl(string uri, string queryString, string signature)
        {
            return string.Format("{0}?{1}&{2}={3}",
                    uri, queryString,
                    OAuthKeys.OAuthSignatureKey, HttpUtility.UrlEncode(signature));
        }
    }
}
